from lib import ip, stdlib
from exception import RouteError

class Route(object):
   def __init__(self, **Keywords):
      self._log = log.StreamLog(stdlib.my_name(self))
      self._route = None
      if "route" in Keywords:
         try:
            self._route = ip.ip(Keywords["route"])
         except ip.IPError as err:
            self._error(err.message)

   def __str__(self):
      return str(self._route).encode('utf-8')

   def _error(self, fmt, *args):
      mesg = stdlib.sprintf(fmt, *args)
      self._log(mesg)
      raise RouteError(mesg)

   length = property(fget = lambda self: self._route.length)
   version = property(fget = lambda self: self._route.value)


class NLRIReachable(Route):
   pass

class NLRIUnreachable(Route):
   pass

class WithdrawnRoute(Route):
   pass


